const { sureChange } = require("../../../../utils/api");

// component/sign-dialog/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    fatherData: {
      type: Object,
      value: {}
    },
    fatherAdd: {
      type: Object,
      value: {}
    },
    goodsid: {
      type: String,
      value: ''
    }

  },

  /**
   * 组件的初始数据
   */
  data: {
    addCheck: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    cancelOrder() {
      this.setData({
        show: false
      })
    },

    //确认订单
    okOrder() {

      if (this.data.addCheck == false) {
        wx.showToast({
          title: '请勾选确认地址信息',
          icon: 'none',
        });
      }
      else {
        this.setData({
          show: false
        })
        let params = {
          gid: this.data.goodsid,
          addid: this.data.fatherAdd.id,
          orderid: this.data.fatherData.id,
          orderctime: this.data.fatherData.create_time,
        }

        sureChange(params).then((res) => {

          if (res.errcode == 0) {

            wx.showToast({
              title: '兑换成功',
              icon: 'success',
              success: (result) => {
                setTimeout(() => {
                  wx.navigateTo({ url: `/pages/successchange/index?orderid=${res.data.orderinfo.id}&time=${res.data.orderinfo.create_time}` })
                }, 1000);
              },

            });

          } else {
            wx.showToast({
              title: res.errmsg,
              icon: 'none',
            });
          }
        })

      }

    },

    clickAdd() {
      this.setData({
        addCheck: !this.data.addCheck
      })

    }
  }
})
